package day3.lesson05
//特殊人群
class SpecialPerson(var name:String)
//特殊人群之一
class Student(var name:String)
//特殊人群之一
class Older(var name:String)
class Worker(var name:String)

class TicketHouse{
  def buyTicket(p:SpecialPerson): Unit ={
    println(p.name+"票到你！！");
  }
}
object MyPredef{
  implicit def object2special(obj:Object):SpecialPerson={
    if(obj.getClass == classOf[Student]){
      val student = obj.asInstanceOf[Student]
      new SpecialPerson(student.name)
    }else if(obj.getClass == classOf[Older]){
      val older = obj.asInstanceOf[Older]
      new SpecialPerson(older.name)
    }else{
      new SpecialPerson("NULL")
    }
  }
}
object Test {
  def main(args: Array[String]): Unit = {
    val house = new TicketHouse()
    val s1 = new Student("yunan")
    val o1 = new Older("zoulaoshi")
    val lulaoshi = new Worker("lulaoshi")

    import MyPredef._

    house.buyTicket(lulaoshi)
  }

}
